home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / fileutil.zip / GETDATE.C < prev    next >
Text File  |  1994-04-16  |  49KB  |  1,858 lines

  1.  
  2. /*  A Bison parser, made from ./getdate.y  */
  3.  
  4. #define YYBISON 1  /* Identify Bison output.  */
  5.  
  6. #define    tAGO    258
  7. #define    tDAY    259
  8. #define    tDAYZONE    260
  9. #define    tID    261
  10. #define    tMERIDIAN    262
  11. #define    tMINUTE_UNIT    263
  12. #define    tMONTH    264
  13. #define    tMONTH_UNIT    265
  14. #define    tSEC_UNIT    266
  15. #define    tSNUMBER    267
  16. #define    tUNUMBER    268
  17. #define    tZONE    269
  18. #define    tDST    270
  19.  
  20. #line 1 "./getdate.y"
  21.  
  22. #define HAVE_FTIME
  23. #undef sgi
  24.  
  25. /* $Revision: 2.1 $
  26. **
  27. **  Originally written by Steven M. Bellovin <smb@research.att.com> while
  28. **  at the University of North Carolina at Chapel Hill.  Later tweaked by
  29. **  a couple of people on Usenet.  Completely overhauled by Rich $alz
  30. **  <rsalz@bbn.com> and Jim Berets <jberets@bbn.com> in August, 1990;
  31. **  send any email to Rich.
  32. **
  33. **  This grammar has eight shift/reduce conflicts.
  34. **
  35. **  This code is in the public domain and has no copyright.
  36. */
  37. /* SUPPRESS 287 on yaccpar_sccsid *//* Unusd static variable */
  38. /* SUPPRESS 288 on yyerrlab *//* Label unused */
  39.  
  40. #ifdef HAVE_CONFIG_H
  41. #include "config.h"
  42. #endif
  43.  
  44. #ifdef __GNUC__
  45. #define alloca __builtin_alloca
  46. #else
  47. #ifdef HAVE_ALLOCA_H
  48. #include <alloca.h>
  49. #else
  50. #ifdef _AIX /* for Bison */
  51.  #pragma alloca
  52. #else
  53. char *alloca ();
  54. #endif
  55. #endif
  56. #endif
  57.  
  58. #include <stdio.h>
  59. #include <ctype.h>
  60.  
  61. /* The code at the top of get_date which figures out the offset of the
  62.    current time zone checks various CPP symbols to see if special
  63.    tricks are need, but defaults to using the gettimeofday system call.
  64.    Include <sys/time.h> if that will be used.  */
  65.  
  66. #if !defined (USG) && !defined (sgi) && !defined (__386BSD__) && !defined(__BORLANDC__)
  67. #include <sys/time.h>
  68. #endif
  69.  
  70. #if    defined(vms)
  71.  
  72. #include <types.h>
  73. #include <time.h>
  74.  
  75. #else
  76.  
  77. #include <sys/types.h>
  78.  
  79. #if    defined(USG) || !defined(HAVE_FTIME)
  80. /*
  81. **  If you need to do a tzset() call to set the
  82. **  timezone, and don't have ftime().
  83. */
  84. struct timeb {
  85.     time_t        time;        /* Seconds since the epoch    */
  86.     unsigned short    millitm;    /* Field not used        */
  87.     short        timezone;
  88.     short        dstflag;    /* Field not used        */
  89. };
  90.  
  91. #else
  92.  
  93. #include <sys/timeb.h>
  94.  
  95. #endif    /* defined(USG) && !defined(HAVE_FTIME) */
  96.  
  97. #if    defined(BSD4_2) || defined(BSD4_1C) || (defined (hp9000) && !defined (hpux))
  98. #include <sys/time.h>
  99. #else
  100. #if defined(_AIX)
  101. #include <sys/time.h>
  102. #endif
  103. #include <time.h>
  104. #endif    /* defined(BSD4_2) */
  105.  
  106. #endif    /* defined(vms) */
  107.  
  108. #if defined (STDC_HEADERS) || defined (USG)
  109. #include <string.h>
  110. #endif
  111.  
  112. #if defined(sgi)
  113. #undef timezone
  114. #endif
  115.  
  116. extern struct tm    *localtime();
  117.  
  118. #define yyparse getdate_yyparse
  119. #define yylex getdate_yylex
  120. #define yyerror getdate_yyerror
  121.  
  122. #if    !defined(lint) && !defined(SABER)
  123. static char RCS[] =
  124.     "$Header: str2date.y,v 2.1 90/09/06 08:15:06 cronan Exp $";
  125. #endif    /* !defined(lint) && !defined(SABER) */
  126.  
  127.  
  128. #define EPOCH        1970
  129. #define HOUR(x)        ((time_t)(x) * 60)
  130. #define SECSPERDAY    (24L * 60L * 60L)
  131.  
  132.  
  133. /*
  134. **  An entry in the lexical lookup table.
  135. */
  136. typedef struct _TABLE {
  137.     char    *name;
  138.     int        type;
  139.     time_t    value;
  140. } TABLE;
  141.  
  142.  
  143. /*
  144. **  Daylight-savings mode:  on, off, or not yet known.
  145. */
  146. typedef enum _DSTMODE {
  147.     DSTon, DSToff, DSTmaybe
  148. } DSTMODE;
  149.  
  150. /*
  151. **  Meridian:  am, pm, or 24-hour style.
  152. */
  153. typedef enum _MERIDIAN {
  154.     MERam, MERpm, MER24
  155. } MERIDIAN;
  156.  
  157.  
  158. /*
  159. **  Global variables.  We could get rid of most of these by using a good
  160. **  union as the yacc stack.  (This routine was originally written before
  161. **  yacc had the %union construct.)  Maybe someday; right now we only use
  162. **  the %union very rarely.
  163. */
  164. static char    *yyInput;
  165. static DSTMODE    yyDSTmode;
  166. static time_t    yyDayOrdinal;
  167. static time_t    yyDayNumber;
  168. static int    yyHaveDate;
  169. static int    yyHaveDay;
  170. static int    yyHaveRel;
  171. static int    yyHaveTime;
  172. static int    yyHaveZone;
  173. static time_t    yyTimezone;
  174. static time_t    yyDay;
  175. static time_t    yyHour;
  176. static time_t    yyMinutes;
  177. static time_t    yyMonth;
  178. static time_t    yySeconds;
  179. static time_t    yyYear;
  180. static MERIDIAN    yyMeridian;
  181. static time_t    yyRelMonth;
  182. static time_t    yyRelSeconds;
  183.  
  184.  
  185. #line 163 "./getdate.y"
  186. typedef union {
  187.     time_t        Number;
  188.     enum _MERIDIAN    Meridian;
  189. } YYSTYPE;
  190.  
  191. #ifndef YYLTYPE
  192. typedef
  193.   struct yyltype
  194.     {
  195.       int timestamp;
  196.       int first_line;
  197.       int first_column;
  198.       int last_line;
  199.       int last_column;
  200.       char *text;
  201.    }
  202.   yyltype;
  203.  
  204. #define YYLTYPE yyltype
  205. #endif
  206.  
  207. #include <stdio.h>
  208.  
  209. #ifndef __STDC__
  210. #define const
  211. #endif
  212.  
  213.  
  214.  
  215. #define    YYFINAL        51
  216. #define    YYFLAG        -32768
  217. #define    YYNTBASE    19
  218.  
  219. #define YYTRANSLATE(x) ((unsigned)(x) <= 270 ? yytranslate[x] : 29)
  220.  
  221. static const char yytranslate[] = {     0,
  222.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  223.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  224.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  225.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  226.      2,     2,     2,    17,     2,     2,    18,     2,     2,     2,
  227.      2,     2,     2,     2,     2,     2,     2,    16,     2,     2,
  228.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  229.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  230.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  231.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  232.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  233.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  234.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  235.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  236.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  237.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  238.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  239.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  240.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  241.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  242.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  243.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  244.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  245.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  246.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  247.      2,     2,     2,     2,     2,     1,     2,     3,     4,     5,
  248.      6,     7,     8,     9,    10,    11,    12,    13,    14,    15
  249. };
  250.  
  251. static const short yyprhs[] = {     0,
  252.      0,     1,     4,     6,     8,    10,    12,    14,    16,    19,
  253.     24,    29,    36,    43,    45,    47,    50,    52,    55,    58,
  254.     62,    68,    72,    75,    80,    83,    87,    90,    92,    95,
  255.     98,   100,   103,   106,   108,   111,   114,   116,   118,   119
  256. };
  257.  
  258. static const short yyrhs[] = {    -1,
  259.     19,    20,     0,    21,     0,    22,     0,    24,     0,    23,
  260.      0,    25,     0,    27,     0,    13,     7,     0,    13,    16,
  261.     13,    28,     0,    13,    16,    13,    12,     0,    13,    16,
  262.     13,    16,    13,    28,     0,    13,    16,    13,    16,    13,
  263.     12,     0,    14,     0,     5,     0,    14,    15,     0,     4,
  264.      0,     4,    17,     0,    13,     4,     0,    13,    18,    13,
  265.      0,    13,    18,    13,    18,    13,     0,    13,    12,    12,
  266.      0,     9,    13,     0,     9,    13,    17,    13,     0,    13,
  267.      9,     0,    13,     9,    13,     0,    26,     3,     0,    26,
  268.      0,    13,     8,     0,    12,     8,     0,     8,     0,    12,
  269.     11,     0,    13,    11,     0,    11,     0,    12,    10,     0,
  270.     13,    10,     0,    10,     0,    13,     0,     0,     7,     0
  271. };
  272.  
  273. #if YYDEBUG != 0
  274. static const short yyrline[] = { 0,
  275.    177,   178,   181,   184,   187,   190,   193,   196,   199,   205,
  276.    211,   218,   224,   234,   238,   242,   249,   253,   257,   263,
  277.    267,   272,   278,   282,   287,   291,   298,   302,   305,   308,
  278.    311,   314,   317,   320,   323,   326,   329,   334,   362,   365
  279. };
  280.  
  281. static const char * const yytname[] = {   "$","error","$illegal.","tAGO","tDAY",
  282. "tDAYZONE","tID","tMERIDIAN","tMINUTE_UNIT","tMONTH","tMONTH_UNIT","tSEC_UNIT",
  283. "tSNUMBER","tUNUMBER","tZONE","tDST","':'","','","'/'","spec","item","time",
  284. "zone","day","date","rel","relunit","number","o_merid",""
  285. };
  286. #endif
  287.  
  288. static const short yyr1[] = {     0,
  289.     19,    19,    20,    20,    20,    20,    20,    20,    21,    21,
  290.     21,    21,    21,    22,    22,    22,    23,    23,    23,    24,
  291.     24,    24,    24,    24,    24,    24,    25,    25,    26,    26,
  292.     26,    26,    26,    26,    26,    26,    26,    27,    28,    28
  293. };
  294.  
  295. static const short yyr2[] = {     0,
  296.      0,     2,     1,     1,     1,     1,     1,     1,     2,     4,
  297.      4,     6,     6,     1,     1,     2,     1,     2,     2,     3,
  298.      5,     3,     2,     4,     2,     3,     2,     1,     2,     2,
  299.      1,     2,     2,     1,     2,     2,     1,     1,     0,     1
  300. };
  301.  
  302. static const short yydefact[] = {     1,
  303.      0,    17,    15,    31,     0,    37,    34,     0,    38,    14,
  304.      2,     3,     4,     6,     5,     7,    28,     8,    18,    23,
  305.     30,    35,    32,    19,     9,    29,    25,    36,    33,     0,
  306.      0,     0,    16,    27,     0,    26,    22,    39,    20,    24,
  307.     40,    11,     0,    10,     0,    39,    21,    13,    12,     0,
  308.      0
  309. };
  310.  
  311. static const short yydefgoto[] = {     1,
  312.     11,    12,    13,    14,    15,    16,    17,    18,    44
  313. };
  314.  
  315. static const short yypact[] = {-32768,
  316.      0,   -15,-32768,-32768,   -10,-32768,-32768,    25,    11,    -8,
  317. -32768,-32768,-32768,-32768,-32768,-32768,    13,-32768,-32768,     7,
  318. -32768,-32768,-32768,-32768,-32768,-32768,     4,-32768,-32768,    14,
  319.     15,    19,-32768,-32768,    24,-32768,-32768,    18,    20,-32768,
  320. -32768,-32768,    26,-32768,    27,    -6,-32768,-32768,-32768,    31,
  321. -32768
  322. };
  323.  
  324. static const short yypgoto[] = {-32768,
  325. -32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,    -5
  326. };
  327.  
  328.  
  329. #define    YYLAST        41
  330.  
  331.  
  332. static const short yytable[] = {    50,
  333.     41,    19,    20,     2,     3,    48,    33,     4,     5,     6,
  334.      7,     8,     9,    10,    24,    34,    36,    25,    26,    27,
  335.     28,    29,    30,    35,    41,    37,    31,    38,    32,    42,
  336.     51,    39,    21,    43,    22,    23,    40,    45,    46,    47,
  337.     49
  338. };
  339.  
  340. static const short yycheck[] = {     0,
  341.      7,    17,    13,     4,     5,    12,    15,     8,     9,    10,
  342.     11,    12,    13,    14,     4,     3,    13,     7,     8,     9,
  343.     10,    11,    12,    17,     7,    12,    16,    13,    18,    12,
  344.      0,    13,     8,    16,    10,    11,    13,    18,    13,    13,
  345.     46
  346. };
  347. /* -*-C-*-  Note some compilers choke on comments on `#line' lines.  */
  348. #line 3 "bison.simple"
  349.  
  350. /* Skeleton output parser for bison,
  351.    Copyright (C) 1984, 1989, 1990 Bob Corbett and Richard Stallman
  352.  
  353.    This program is free software; you can redistribute it and/or modify
  354.    it under the terms of the GNU General Public License as published by
  355.    the Free Software Foundation; either version 1, or (at your option)
  356.    any later version.
  357.  
  358.    This program is distributed in the hope that it will be useful,
  359.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  360.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  361.    GNU General Public License for more details.
  362.  
  363.    You should have received a copy of the GNU General Public License
  364.    along with this program; if not, write to the Free Software
  365.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  366.  
  367.  
  368. #ifndef alloca
  369. #ifdef __GNUC__
  370. #define alloca __builtin_alloca
  371. #else /* not GNU C.  */
  372. #if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__)
  373. #include <alloca.h>
  374. #else /* not sparc */
  375. #if defined (MSDOS) && !defined (__TURBOC__)
  376. #include <malloc.h>
  377. #else /* not MSDOS, or __TURBOC__ */
  378. #if defined(_AIX)
  379. #include <malloc.h>
  380.  #pragma alloca
  381. #endif /* not _AIX */
  382. #endif /* not MSDOS, or __TURBOC__ */
  383. #endif /* not sparc.  */
  384. #endif /* not GNU C.  */
  385. #endif /* alloca not defined.  */
  386.  
  387. /* This is the parser code that is written into each bison parser
  388.   when the %semantic_parser declaration is not specified in the grammar.
  389.   It was written by Richard Stallman by simplifying the hairy parser
  390.   used when %semantic_parser is specified.  */
  391.  
  392. /* Note: there must be only one dollar sign in this file.
  393.    It is replaced by the list of actions, each action
  394.    as one case of the switch.  */
  395.  
  396. #define yyerrok        (yyerrstatus = 0)
  397. #define yyclearin    (yychar = YYEMPTY)
  398. #define YYEMPTY        -2
  399. #define YYEOF        0
  400. #define YYACCEPT    return(0)
  401. #define YYABORT     return(1)
  402. #define YYERROR        goto yyerrlab1
  403. /* Like YYERROR except do call yyerror.
  404.    This remains here temporarily to ease the
  405.    transition to the new meaning of YYERROR, for GCC.
  406.    Once GCC version 2 has supplanted version 1, this can go.  */
  407. #define YYFAIL        goto yyerrlab
  408. #define YYRECOVERING()  (!!yyerrstatus)
  409. #define YYBACKUP(token, value) \
  410. do                                \
  411.   if (yychar == YYEMPTY && yylen == 1)                \
  412.     { yychar = (token), yylval = (value);            \
  413.       yychar1 = YYTRANSLATE (yychar);                \
  414.       YYPOPSTACK;                        \
  415.       goto yybackup;                        \
  416.     }                                \
  417.   else                                \
  418.     { yyerror ("syntax error: cannot back up"); YYERROR; }    \
  419. while (0)
  420.  
  421. #define YYTERROR    1
  422. #define YYERRCODE    256
  423.  
  424. #ifndef YYPURE
  425. #define YYLEX        yylex()
  426. #endif
  427.  
  428. #ifdef YYPURE
  429. #ifdef YYLSP_NEEDED
  430. #define YYLEX        yylex(&yylval, &yylloc)
  431. #else
  432. #define YYLEX        yylex(&yylval)
  433. #endif
  434. #endif
  435.  
  436. /* If nonreentrant, generate the variables here */
  437.  
  438. #ifndef YYPURE
  439.  
  440. int    yychar;            /*  the lookahead symbol        */
  441. YYSTYPE    yylval;            /*  the semantic value of the        */
  442.                 /*  lookahead symbol            */
  443.  
  444. #ifdef YYLSP_NEEDED
  445. YYLTYPE yylloc;            /*  location data for the lookahead    */
  446.                 /*  symbol                */
  447. #endif
  448.  
  449. int yynerrs;            /*  number of parse errors so far       */
  450. #endif  /* not YYPURE */
  451.  
  452. #if YYDEBUG != 0
  453. int yydebug;            /*  nonzero means print parse trace    */
  454. /* Since this is uninitialized, it does not stop multiple parsers
  455.    from coexisting.  */
  456. #endif
  457.  
  458. /*  YYINITDEPTH indicates the initial size of the parser's stacks    */
  459.  
  460. #ifndef    YYINITDEPTH
  461. #define YYINITDEPTH 200
  462. #endif
  463.  
  464. /*  YYMAXDEPTH is the maximum size the stacks can grow to
  465.     (effective only if the built-in stack extension method is used).  */
  466.  
  467. #if YYMAXDEPTH == 0
  468. #undef YYMAXDEPTH
  469. #endif
  470.  
  471. #ifndef YYMAXDEPTH
  472. #define YYMAXDEPTH 10000
  473. #endif
  474.  
  475. #if __GNUC__ > 1        /* GNU C and GNU C++ define this.  */
  476. #define __yy_bcopy(FROM,TO,COUNT)    __builtin_memcpy(TO,FROM,COUNT)
  477. #else                /* not GNU C or C++ */
  478. #ifndef __cplusplus
  479.  
  480. /* This is the most reliable way to avoid incompatibilities
  481.    in available built-in functions on various systems.  */
  482. static void
  483. __yy_bcopy (from, to, count)
  484.      char *from;
  485.      char *to;
  486.      int count;
  487. {
  488.   register char *f = from;
  489.   register char *t = to;
  490.   register int i = count;
  491.  
  492.   while (i-- > 0)
  493.     *t++ = *f++;
  494. }
  495.  
  496. #else /* __cplusplus */
  497.  
  498. /* This is the most reliable way to avoid incompatibilities
  499.    in available built-in functions on various systems.  */
  500. static void
  501. __yy_bcopy (char *from, char *to, int count)
  502. {
  503.   register char *f = from;
  504.   register char *t = to;
  505.   register int i = count;
  506.  
  507.   while (i-- > 0)
  508.     *t++ = *f++;
  509. }
  510.  
  511. #endif
  512. #endif
  513.  
  514. #line 169 "bison.simple"
  515. int
  516. yyparse()
  517. {
  518.   register int yystate;
  519.   register int yyn;
  520.   register short *yyssp;
  521.   register YYSTYPE *yyvsp;
  522.   int yyerrstatus;    /*  number of tokens to shift before error messages enabled */
  523.   int yychar1;        /*  lookahead token as an internal (translated) token number */
  524.  
  525.   short    yyssa[YYINITDEPTH];    /*  the state stack            */
  526.   YYSTYPE yyvsa[YYINITDEPTH];    /*  the semantic value stack        */
  527.  
  528.   short *yyss = yyssa;        /*  refer to the stacks thru separate pointers */
  529.   YYSTYPE *yyvs = yyvsa;    /*  to allow yyoverflow to reallocate them elsewhere */
  530.  
  531. #ifdef YYLSP_NEEDED
  532.   YYLTYPE yylsa[YYINITDEPTH];    /*  the location stack            */
  533.   YYLTYPE *yyls = yylsa;
  534.   YYLTYPE *yylsp;
  535.  
  536. #define YYPOPSTACK   (yyvsp--, yyssp--, yylsp--)
  537. #else
  538. #define YYPOPSTACK   (yyvsp--, yyssp--)
  539. #endif
  540.  
  541.   int yystacksize = YYINITDEPTH;
  542.  
  543. #ifdef YYPURE
  544.   int yychar;
  545.   YYSTYPE yylval;
  546.   int yynerrs;
  547. #ifdef YYLSP_NEEDED
  548.   YYLTYPE yylloc;
  549. #endif
  550. #endif
  551.  
  552.   YYSTYPE yyval;        /*  the variable used to return        */
  553.                 /*  semantic values from the action    */
  554.                 /*  routines                */
  555.  
  556.   int yylen;
  557.  
  558. #if YYDEBUG != 0
  559.   if (yydebug)
  560.     fprintf(stderr, "Starting parse\n");
  561. #endif
  562.  
  563.   yystate = 0;
  564.   yyerrstatus = 0;
  565.   yynerrs = 0;
  566.   yychar = YYEMPTY;        /* Cause a token to be read.  */
  567.  
  568.   /* Initialize stack pointers.
  569.      Waste one element of value and location stack
  570.      so that they stay on the same level as the state stack.  */
  571.  
  572.   yyssp = yyss - 1;
  573.   yyvsp = yyvs;
  574. #ifdef YYLSP_NEEDED
  575.   yylsp = yyls;
  576. #endif
  577.  
  578. /* Push a new state, which is found in  yystate  .  */
  579. /* In all cases, when you get here, the value and location stacks
  580.    have just been pushed. so pushing a state here evens the stacks.  */
  581. yynewstate:
  582.  
  583.   *++yyssp = yystate;
  584.  
  585.   if (yyssp >= yyss + yystacksize - 1)
  586.     {
  587.       /* Give user a chance to reallocate the stack */
  588.       /* Use copies of these so that the &'s don't force the real ones into memory. */
  589.       YYSTYPE *yyvs1 = yyvs;
  590.       short *yyss1 = yyss;
  591. #ifdef YYLSP_NEEDED
  592.       YYLTYPE *yyls1 = yyls;
  593. #endif
  594.  
  595.       /* Get the current used size of the three stacks, in elements.  */
  596.       int size = yyssp - yyss + 1;
  597.  
  598. #ifdef yyoverflow
  599.       /* Each stack pointer address is followed by the size of
  600.      the data in use in that stack, in bytes.  */
  601.       yyoverflow("parser stack overflow",
  602.          &yyss1, size * sizeof (*yyssp),
  603.          &yyvs1, size * sizeof (*yyvsp),
  604. #ifdef YYLSP_NEEDED
  605.          &yyls1, size * sizeof (*yylsp),
  606. #endif
  607.          &yystacksize);
  608.  
  609.       yyss = yyss1; yyvs = yyvs1;
  610. #ifdef YYLSP_NEEDED
  611.       yyls = yyls1;
  612. #endif
  613. #else /* no yyoverflow */
  614.       /* Extend the stack our own way.  */
  615.       if (yystacksize >= YYMAXDEPTH)
  616.     {
  617.       yyerror("parser stack overflow");
  618.       return 2;
  619.     }
  620.       yystacksize *= 2;
  621.       if (yystacksize > YYMAXDEPTH)
  622.     yystacksize = YYMAXDEPTH;
  623.       yyss = (short *) alloca (yystacksize * sizeof (*yyssp));
  624.       __yy_bcopy ((char *)yyss1, (char *)yyss, size * sizeof (*yyssp));
  625.       yyvs = (YYSTYPE *) alloca (yystacksize * sizeof (*yyvsp));
  626.       __yy_bcopy ((char *)yyvs1, (char *)yyvs, size * sizeof (*yyvsp));
  627. #ifdef YYLSP_NEEDED
  628.       yyls = (YYLTYPE *) alloca (yystacksize * sizeof (*yylsp));
  629.       __yy_bcopy ((char *)yyls1, (char *)yyls, size * sizeof (*yylsp));
  630. #endif
  631. #endif /* no yyoverflow */
  632.  
  633.       yyssp = yyss + size - 1;
  634.       yyvsp = yyvs + size - 1;
  635. #ifdef YYLSP_NEEDED
  636.       yylsp = yyls + size - 1;
  637. #endif
  638.  
  639. #if YYDEBUG != 0
  640.       if (yydebug)
  641.     fprintf(stderr, "Stack size increased to %d\n", yystacksize);
  642. #endif
  643.  
  644.       if (yyssp >= yyss + yystacksize - 1)
  645.     YYABORT;
  646.     }
  647.  
  648. #if YYDEBUG != 0
  649.   if (yydebug)
  650.     fprintf(stderr, "Entering state %d\n", yystate);
  651. #endif
  652.  
  653.  yybackup:
  654.  
  655. /* Do appropriate processing given the current state.  */
  656. /* Read a lookahead token if we need one and don't already have one.  */
  657. /* yyresume: */
  658.  
  659.   /* First try to decide what to do without reference to lookahead token.  */
  660.  
  661.   yyn = yypact[yystate];
  662.   if (yyn == YYFLAG)
  663.     goto yydefault;
  664.  
  665.   /* Not known => get a lookahead token if don't already have one.  */
  666.  
  667.   /* yychar is either YYEMPTY or YYEOF
  668.      or a valid token in external form.  */
  669.  
  670.   if (yychar == YYEMPTY)
  671.     {
  672. #if YYDEBUG != 0
  673.       if (yydebug)
  674.     fprintf(stderr, "Reading a token: ");
  675. #endif
  676.       yychar = YYLEX;
  677.     }
  678.  
  679.   /* Convert token to internal form (in yychar1) for indexing tables with */
  680.  
  681.   if (yychar <= 0)        /* This means end of input. */
  682.     {
  683.       yychar1 = 0;
  684.       yychar = YYEOF;        /* Don't call YYLEX any more */
  685.  
  686. #if YYDEBUG != 0
  687.       if (yydebug)
  688.     fprintf(stderr, "Now at end of input.\n");
  689. #endif
  690.     }
  691.   else
  692.     {
  693.       yychar1 = YYTRANSLATE(yychar);
  694.  
  695. #if YYDEBUG != 0
  696.       if (yydebug)
  697.     {
  698.       fprintf (stderr, "Next token is %d (%s", yychar, yytname[yychar1]);
  699.       /* Give the individual parser a way to print the precise meaning
  700.          of a token, for further debugging info.  */
  701. #ifdef YYPRINT
  702.       YYPRINT (stderr, yychar, yylval);
  703. #endif
  704.       fprintf (stderr, ")\n");
  705.     }
  706. #endif
  707.     }
  708.  
  709.   yyn += yychar1;
  710.   if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
  711.     goto yydefault;
  712.  
  713.   yyn = yytable[yyn];
  714.  
  715.   /* yyn is what to do for this token type in this state.
  716.      Negative => reduce, -yyn is rule number.
  717.      Positive => shift, yyn is new state.
  718.        New state is final state => don't bother to shift,
  719.        just return success.
  720.      0, or most negative number => error.  */
  721.  
  722.   if (yyn < 0)
  723.     {
  724.       if (yyn == YYFLAG)
  725.     goto yyerrlab;
  726.       yyn = -yyn;
  727.       goto yyreduce;
  728.     }
  729.   else if (yyn == 0)
  730.     goto yyerrlab;
  731.  
  732.   if (yyn == YYFINAL)
  733.     YYACCEPT;
  734.  
  735.   /* Shift the lookahead token.  */
  736.  
  737. #if YYDEBUG != 0
  738.   if (yydebug)
  739.     fprintf(stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]);
  740. #endif
  741.  
  742.   /* Discard the token being shifted unless it is eof.  */
  743.   if (yychar != YYEOF)
  744.     yychar = YYEMPTY;
  745.  
  746.   *++yyvsp = yylval;
  747. #ifdef YYLSP_NEEDED
  748.   *++yylsp = yylloc;
  749. #endif
  750.  
  751.   /* count tokens shifted since error; after three, turn off error status.  */
  752.   if (yyerrstatus) yyerrstatus--;
  753.  
  754.   yystate = yyn;
  755.   goto yynewstate;
  756.  
  757. /* Do the default action for the current state.  */
  758. yydefault:
  759.  
  760.   yyn = yydefact[yystate];
  761.   if (yyn == 0)
  762.     goto yyerrlab;
  763.  
  764. /* Do a reduction.  yyn is the number of a rule to reduce with.  */
  765. yyreduce:
  766.   yylen = yyr2[yyn];
  767.   yyval = yyvsp[1-yylen]; /* implement default value of the action */
  768.  
  769. #if YYDEBUG != 0
  770.   if (yydebug)
  771.     {
  772.       int i;
  773.  
  774.       fprintf (stderr, "Reducing via rule %d (line %d), ",
  775.            yyn, yyrline[yyn]);
  776.  
  777.       /* Print the symboles being reduced, and their result.  */
  778.       for (i = yyprhs[yyn]; yyrhs[i] > 0; i++)
  779.     fprintf (stderr, "%s ", yytname[yyrhs[i]]);
  780.       fprintf (stderr, " -> %s\n", yytname[yyr1[yyn]]);
  781.     }
  782. #endif
  783.  
  784.  
  785.   switch (yyn) {
  786.  
  787. case 3:
  788. #line 181 "./getdate.y"
  789. {
  790.         yyHaveTime++;
  791.     ;
  792.     break;}
  793. case 4:
  794. #line 184 "./getdate.y"
  795. {
  796.         yyHaveZone++;
  797.     ;
  798.     break;}
  799. case 5:
  800. #line 187 "./getdate.y"
  801. {
  802.         yyHaveDate++;
  803.     ;
  804.     break;}
  805. case 6:
  806. #line 190 "./getdate.y"
  807. {
  808.         yyHaveDay++;
  809.     ;
  810.     break;}
  811. case 7:
  812. #line 193 "./getdate.y"
  813. {
  814.         yyHaveRel++;
  815.     ;
  816.     break;}
  817. case 9:
  818. #line 199 "./getdate.y"
  819. {
  820.         yyHour = yyvsp[-1].Number;
  821.         yyMinutes = 0;
  822.         yySeconds = 0;
  823.         yyMeridian = yyvsp[0].Meridian;
  824.     ;
  825.     break;}
  826. case 10:
  827. #line 205 "./getdate.y"
  828. {
  829.         yyHour = yyvsp[-3].Number;
  830.         yyMinutes = yyvsp[-1].Number;
  831.         yySeconds = 0;
  832.         yyMeridian = yyvsp[0].Meridian;
  833.     ;
  834.     break;}
  835. case 11:
  836. #line 211 "./getdate.y"
  837. {
  838.         yyHour = yyvsp[-3].Number;
  839.         yyMinutes = yyvsp[-1].Number;
  840.         yyMeridian = MER24;
  841.         yyDSTmode = DSToff;
  842.         yyTimezone = - (yyvsp[0].Number % 100 + (yyvsp[0].Number / 100) * 60);
  843.     ;
  844.     break;}
  845. case 12:
  846. #line 218 "./getdate.y"
  847. {
  848.         yyHour = yyvsp[-5].Number;
  849.         yyMinutes = yyvsp[-3].Number;
  850.         yySeconds = yyvsp[-1].Number;
  851.         yyMeridian = yyvsp[0].Meridian;
  852.     ;
  853.     break;}
  854. case 13:
  855. #line 224 "./getdate.y"
  856. {
  857.         yyHour = yyvsp[-5].Number;
  858.         yyMinutes = yyvsp[-3].Number;
  859.         yySeconds = yyvsp[-1].Number;
  860.         yyMeridian = MER24;
  861.         yyDSTmode = DSToff;
  862.         yyTimezone = - (yyvsp[0].Number % 100 + (yyvsp[0].Number / 100) * 60);
  863.     ;
  864.     break;}
  865. case 14:
  866. #line 234 "./getdate.y"
  867. {
  868.         yyTimezone = yyvsp[0].Number;
  869.         yyDSTmode = DSToff;
  870.     ;
  871.     break;}
  872. case 15:
  873. #line 238 "./getdate.y"
  874. {
  875.         yyTimezone = yyvsp[0].Number;
  876.         yyDSTmode = DSTon;
  877.     ;
  878.     break;}
  879. case 16:
  880. #line 243 "./getdate.y"
  881. {
  882.         yyTimezone = yyvsp[-1].Number;
  883.         yyDSTmode = DSTon;
  884.     ;
  885.     break;}
  886. case 17:
  887. #line 249 "./getdate.y"
  888. {
  889.         yyDayOrdinal = 1;
  890.         yyDayNumber = yyvsp[0].Number;
  891.     ;
  892.     break;}
  893. case 18:
  894. #line 253 "./getdate.y"
  895. {
  896.         yyDayOrdinal = 1;
  897.         yyDayNumber = yyvsp[-1].Number;
  898.     ;
  899.     break;}
  900. case 19:
  901. #line 257 "./getdate.y"
  902. {
  903.         yyDayOrdinal = yyvsp[-1].Number;
  904.         yyDayNumber = yyvsp[0].Number;
  905.     ;
  906.     break;}
  907. case 20:
  908. #line 263 "./getdate.y"
  909. {
  910.         yyMonth = yyvsp[-2].Number;
  911.         yyDay = yyvsp[0].Number;
  912.     ;
  913.     break;}
  914. case 21:
  915. #line 267 "./getdate.y"
  916. {
  917.         yyMonth = yyvsp[-4].Number;
  918.         yyDay = yyvsp[-2].Number;
  919.         yyYear = yyvsp[0].Number;
  920.     ;
  921.     break;}
  922. case 22:
  923. #line 272 "./getdate.y"
  924. {
  925.         /* ISO 8601 format.  yyyy-mm-dd.  */
  926.         yyYear = yyvsp[-2].Number;
  927.         yyMonth = -yyvsp[-1].Number;
  928.         yyDay = -yyvsp[0].Number;
  929.     ;
  930.     break;}
  931. case 23:
  932. #line 278 "./getdate.y"
  933. {
  934.         yyMonth = yyvsp[-1].Number;
  935.         yyDay = yyvsp[0].Number;
  936.     ;
  937.     break;}
  938. case 24:
  939. #line 282 "./getdate.y"
  940. {
  941.         yyMonth = yyvsp[-3].Number;
  942.         yyDay = yyvsp[-2].Number;
  943.         yyYear = yyvsp[0].Number;
  944.     ;
  945.     break;}
  946. case 25:
  947. #line 287 "./getdate.y"
  948. {
  949.         yyMonth = yyvsp[0].Number;
  950.         yyDay = yyvsp[-1].Number;
  951.     ;
  952.     break;}
  953. case 26:
  954. #line 291 "./getdate.y"
  955. {
  956.         yyMonth = yyvsp[-1].Number;
  957.         yyDay = yyvsp[-2].Number;
  958.         yyYear = yyvsp[0].Number;
  959.     ;
  960.     break;}
  961. case 27:
  962. #line 298 "./getdate.y"
  963. {
  964.         yyRelSeconds = -yyRelSeconds;
  965.         yyRelMonth = -yyRelMonth;
  966.     ;
  967.     break;}
  968. case 29:
  969. #line 305 "./getdate.y"
  970. {
  971.         yyRelSeconds += yyvsp[-1].Number * yyvsp[0].Number * 60L;
  972.     ;
  973.     break;}
  974. case 30:
  975. #line 308 "./getdate.y"
  976. {
  977.         yyRelSeconds += yyvsp[-1].Number * yyvsp[0].Number * 60L;
  978.     ;
  979.     break;}
  980. case 31:
  981. #line 311 "./getdate.y"
  982. {
  983.         yyRelSeconds += yyvsp[0].Number * 60L;
  984.     ;
  985.     break;}
  986. case 32:
  987. #line 314 "./getdate.y"
  988. {
  989.         yyRelSeconds += yyvsp[-1].Number;
  990.     ;
  991.     break;}
  992. case 33:
  993. #line 317 "./getdate.y"
  994. {
  995.         yyRelSeconds += yyvsp[-1].Number;
  996.     ;
  997.     break;}
  998. case 34:
  999. #line 320 "./getdate.y"
  1000. {
  1001.         yyRelSeconds++;
  1002.     ;
  1003.     break;}
  1004. case 35:
  1005. #line 323 "./getdate.y"
  1006. {
  1007.         yyRelMonth += yyvsp[-1].Number * yyvsp[0].Number;
  1008.     ;
  1009.     break;}
  1010. case 36:
  1011. #line 326 "./getdate.y"
  1012. {
  1013.         yyRelMonth += yyvsp[-1].Number * yyvsp[0].Number;
  1014.     ;
  1015.     break;}
  1016. case 37:
  1017. #line 329 "./getdate.y"
  1018. {
  1019.         yyRelMonth += yyvsp[0].Number;
  1020.     ;
  1021.     break;}
  1022. case 38:
  1023. #line 334 "./getdate.y"
  1024. {
  1025.         if (yyHaveTime && yyHaveDate && !yyHaveRel)
  1026.         yyYear = yyvsp[0].Number;
  1027.         else {
  1028.         if(yyvsp[0].Number>10000) {
  1029.             time_t date_part;
  1030.  
  1031.             date_part= yyvsp[0].Number/10000;
  1032.             yyHaveDate++;
  1033.             yyDay= (date_part)%100;
  1034.             yyMonth= (date_part/100)%100;
  1035.             yyYear = date_part/10000;
  1036.         } 
  1037.             yyHaveTime++;
  1038.         if (yyvsp[0].Number < 100) {
  1039.             yyHour = yyvsp[0].Number;
  1040.             yyMinutes = 0;
  1041.         }
  1042.         else {
  1043.             yyHour = yyvsp[0].Number / 100;
  1044.             yyMinutes = yyvsp[0].Number % 100;
  1045.         }
  1046.         yySeconds = 0;
  1047.         yyMeridian = MER24;
  1048.         }
  1049.     ;
  1050.     break;}
  1051. case 39:
  1052. #line 362 "./getdate.y"
  1053. {
  1054.         yyval.Meridian = MER24;
  1055.     ;
  1056.     break;}
  1057. case 40:
  1058. #line 365 "./getdate.y"
  1059. {
  1060.         yyval.Meridian = yyvsp[0].Meridian;
  1061.     ;
  1062.     break;}
  1063. }
  1064.    /* the action file gets copied in in place of this dollarsign */
  1065. #line 440 "bison.simple"
  1066.  
  1067.   yyvsp -= yylen;
  1068.   yyssp -= yylen;
  1069. #ifdef YYLSP_NEEDED
  1070.   yylsp -= yylen;
  1071. #endif
  1072.  
  1073. #if YYDEBUG != 0
  1074.   if (yydebug)
  1075.     {
  1076.       short *ssp1 = yyss - 1;
  1077.       fprintf (stderr, "state stack now");
  1078.       while (ssp1 != yyssp)
  1079.     fprintf (stderr, " %d", *++ssp1);
  1080.       fprintf (stderr, "\n");
  1081.     }
  1082. #endif
  1083.  
  1084.   *++yyvsp = yyval;
  1085.  
  1086. #ifdef YYLSP_NEEDED
  1087.   yylsp++;
  1088.   if (yylen == 0)
  1089.     {
  1090.       yylsp->first_line = yylloc.first_line;
  1091.       yylsp->first_column = yylloc.first_column;
  1092.       yylsp->last_line = (yylsp-1)->last_line;
  1093.       yylsp->last_column = (yylsp-1)->last_column;
  1094.       yylsp->text = 0;
  1095.     }
  1096.   else
  1097.     {
  1098.       yylsp->last_line = (yylsp+yylen-1)->last_line;
  1099.       yylsp->last_column = (yylsp+yylen-1)->last_column;
  1100.     }
  1101. #endif
  1102.  
  1103.   /* Now "shift" the result of the reduction.
  1104.      Determine what state that goes to,
  1105.      based on the state we popped back to
  1106.      and the rule number reduced by.  */
  1107.  
  1108.   yyn = yyr1[yyn];
  1109.  
  1110.   yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
  1111.   if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
  1112.     yystate = yytable[yystate];
  1113.   else
  1114.     yystate = yydefgoto[yyn - YYNTBASE];
  1115.  
  1116.   goto yynewstate;
  1117.  
  1118. yyerrlab:   /* here on detecting error */
  1119.  
  1120.   if (! yyerrstatus)
  1121.     /* If not already recovering from an error, report this error.  */
  1122.     {
  1123.       ++yynerrs;
  1124.  
  1125. #ifdef YYERROR_VERBOSE
  1126.       yyn = yypact[yystate];
  1127.  
  1128.       if (yyn > YYFLAG && yyn < YYLAST)
  1129.     {
  1130.       int size = 0;
  1131.       char *msg;
  1132.       int x, count;
  1133.  
  1134.       count = 0;
  1135.       for (x = 0; x < (sizeof(yytname) / sizeof(char *)); x++)
  1136.         if (yycheck[x + yyn] == x)
  1137.           size += strlen(yytname[x]) + 15, count++;
  1138.       msg = (char *) malloc(size + 15);
  1139.       if (msg != 0)
  1140.         {
  1141.           strcpy(msg, "parse error");
  1142.  
  1143.           if (count < 5)
  1144.         {
  1145.           count = 0;
  1146.           for (x = 0; x < (sizeof(yytname) / sizeof(char *)); x++)
  1147.             if (yycheck[x + yyn] == x)
  1148.               {
  1149.             strcat(msg, count == 0 ? ", expecting `" : " or `");
  1150.             strcat(msg, yytname[x]);
  1151.             strcat(msg, "'");
  1152.             count++;
  1153.               }
  1154.         }
  1155.           yyerror(msg);
  1156.           free(msg);
  1157.         }
  1158.       else
  1159.         yyerror ("parse error; also virtual memory exceeded");
  1160.     }
  1161.       else
  1162. #endif /* YYERROR_VERBOSE */
  1163.     yyerror("parse error");
  1164.     }
  1165.  
  1166. yyerrlab1:   /* here on error raised explicitly by an action */
  1167.  
  1168.   if (yyerrstatus == 3)
  1169.     {
  1170.       /* if just tried and failed to reuse lookahead token after an error, discard it.  */
  1171.  
  1172.       /* return failure if at end of input */
  1173.       if (yychar == YYEOF)
  1174.     YYABORT;
  1175.  
  1176. #if YYDEBUG != 0
  1177.       if (yydebug)
  1178.     fprintf(stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1]);
  1179. #endif
  1180.  
  1181.       yychar = YYEMPTY;
  1182.     }
  1183.  
  1184.   /* Else will try to reuse lookahead token
  1185.      after shifting the error token.  */
  1186.  
  1187.   yyerrstatus = 3;        /* Each real token shifted decrements this */
  1188.  
  1189.   goto yyerrhandle;
  1190.  
  1191. yyerrdefault:  /* current state does not do anything special for the error token. */
  1192.  
  1193. #if 0
  1194.   /* This is wrong; only states that explicitly want error tokens
  1195.      should shift them.  */
  1196.   yyn = yydefact[yystate];  /* If its default is to accept any token, ok.  Otherwise pop it.*/
  1197.   if (yyn) goto yydefault;
  1198. #endif
  1199.  
  1200. yyerrpop:   /* pop the current state because it cannot handle the error token */
  1201.  
  1202.   if (yyssp == yyss) YYABORT;
  1203.   yyvsp--;
  1204.   yystate = *--yyssp;
  1205. #ifdef YYLSP_NEEDED
  1206.   yylsp--;
  1207. #endif
  1208.  
  1209. #if YYDEBUG != 0
  1210.   if (yydebug)
  1211.     {
  1212.       short *ssp1 = yyss - 1;
  1213.       fprintf (stderr, "Error: state stack now");
  1214.       while (ssp1 != yyssp)
  1215.     fprintf (stderr, " %d", *++ssp1);
  1216.       fprintf (stderr, "\n");
  1217.     }
  1218. #endif
  1219.  
  1220. yyerrhandle:
  1221.  
  1222.   yyn = yypact[yystate];
  1223.   if (yyn == YYFLAG)
  1224.     goto yyerrdefault;
  1225.  
  1226.   yyn += YYTERROR;
  1227.   if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
  1228.     goto yyerrdefault;
  1229.  
  1230.   yyn = yytable[yyn];
  1231.   if (yyn < 0)
  1232.     {
  1233.       if (yyn == YYFLAG)
  1234.     goto yyerrpop;
  1235.       yyn = -yyn;
  1236.       goto yyreduce;
  1237.     }
  1238.   else if (yyn == 0)
  1239.     goto yyerrpop;
  1240.  
  1241.   if (yyn == YYFINAL)
  1242.     YYACCEPT;
  1243.  
  1244. #if YYDEBUG != 0
  1245.   if (yydebug)
  1246.     fprintf(stderr, "Shifting error token, ");
  1247. #endif
  1248.  
  1249.   *++yyvsp = yylval;
  1250. #ifdef YYLSP_NEEDED
  1251.   *++yylsp = yylloc;
  1252. #endif
  1253.  
  1254.   yystate = yyn;
  1255.   goto yynewstate;
  1256. }
  1257. #line 370 "./getdate.y"
  1258.  
  1259.  
  1260. /* Month and day table. */
  1261. static TABLE const MonthDayTable[] = {
  1262.     { "january",    tMONTH,  1 },
  1263.     { "february",    tMONTH,  2 },
  1264.     { "march",        tMONTH,  3 },
  1265.     { "april",        tMONTH,  4 },
  1266.     { "may",        tMONTH,  5 },
  1267.     { "june",        tMONTH,  6 },
  1268.     { "july",        tMONTH,  7 },
  1269.     { "august",        tMONTH,  8 },
  1270.     { "september",    tMONTH,  9 },
  1271.     { "sept",        tMONTH,  9 },
  1272.     { "october",    tMONTH, 10 },
  1273.     { "november",    tMONTH, 11 },
  1274.     { "december",    tMONTH, 12 },
  1275.     { "sunday",        tDAY, 0 },
  1276.     { "monday",        tDAY, 1 },
  1277.     { "tuesday",    tDAY, 2 },
  1278.     { "tues",        tDAY, 2 },
  1279.     { "wednesday",    tDAY, 3 },
  1280.     { "wednes",        tDAY, 3 },
  1281.     { "thursday",    tDAY, 4 },
  1282.     { "thur",        tDAY, 4 },
  1283.     { "thurs",        tDAY, 4 },
  1284.     { "friday",        tDAY, 5 },
  1285.     { "saturday",    tDAY, 6 },
  1286.     { NULL }
  1287. };
  1288.  
  1289. /* Time units table. */
  1290. static TABLE const UnitsTable[] = {
  1291.     { "year",        tMONTH_UNIT,    12 },
  1292.     { "month",        tMONTH_UNIT,    1 },
  1293.     { "fortnight",    tMINUTE_UNIT,    14 * 24 * 60 },
  1294.     { "week",        tMINUTE_UNIT,    7 * 24 * 60 },
  1295.     { "day",        tMINUTE_UNIT,    1 * 24 * 60 },
  1296.     { "hour",        tMINUTE_UNIT,    60 },
  1297.     { "minute",        tMINUTE_UNIT,    1 },
  1298.     { "min",        tMINUTE_UNIT,    1 },
  1299.     { "second",        tSEC_UNIT,    1 },
  1300.     { "sec",        tSEC_UNIT,    1 },
  1301.     { NULL }
  1302. };
  1303.  
  1304. /* Assorted relative-time words. */
  1305. static TABLE const OtherTable[] = {
  1306.     { "tomorrow",    tMINUTE_UNIT,    1 * 24 * 60 },
  1307.     { "yesterday",    tMINUTE_UNIT,    -1 * 24 * 60 },
  1308.     { "today",        tMINUTE_UNIT,    0 },
  1309.     { "now",        tMINUTE_UNIT,    0 },
  1310.     { "last",        tUNUMBER,    -1 },
  1311.     { "this",        tMINUTE_UNIT,    0 },
  1312.     { "next",        tUNUMBER,    2 },
  1313.     { "first",        tUNUMBER,    1 },
  1314. /*  { "second",        tUNUMBER,    2 }, */
  1315.     { "third",        tUNUMBER,    3 },
  1316.     { "fourth",        tUNUMBER,    4 },
  1317.     { "fifth",        tUNUMBER,    5 },
  1318.     { "sixth",        tUNUMBER,    6 },
  1319.     { "seventh",    tUNUMBER,    7 },
  1320.     { "eighth",        tUNUMBER,    8 },
  1321.     { "ninth",        tUNUMBER,    9 },
  1322.     { "tenth",        tUNUMBER,    10 },
  1323.     { "eleventh",    tUNUMBER,    11 },
  1324.     { "twelfth",    tUNUMBER,    12 },
  1325.     { "ago",        tAGO,    1 },
  1326.     { NULL }
  1327. };
  1328.  
  1329. /* The timezone table. */
  1330. /* Some of these are commented out because a time_t can't store a float. */
  1331. static TABLE const TimezoneTable[] = {
  1332.     { "gmt",    tZONE,     HOUR( 0) },    /* Greenwich Mean */
  1333.     { "ut",    tZONE,     HOUR( 0) },    /* Universal (Coordinated) */
  1334.     { "utc",    tZONE,     HOUR( 0) },
  1335.     { "wet",    tZONE,     HOUR( 0) },    /* Western European */
  1336.     { "bst",    tDAYZONE,  HOUR( 0) },    /* British Summer */
  1337.     { "wat",    tZONE,     HOUR( 1) },    /* West Africa */
  1338.     { "at",    tZONE,     HOUR( 2) },    /* Azores */
  1339. #if    0
  1340.     /* For completeness.  BST is also British Summer, and GST is
  1341.      * also Guam Standard. */
  1342.     { "bst",    tZONE,     HOUR( 3) },    /* Brazil Standard */
  1343.     { "gst",    tZONE,     HOUR( 3) },    /* Greenland Standard */
  1344. #endif
  1345. #if 0
  1346.     { "nft",    tZONE,     HOUR(3.5) },    /* Newfoundland */
  1347.     { "nst",    tZONE,     HOUR(3.5) },    /* Newfoundland Standard */
  1348.     { "ndt",    tDAYZONE,  HOUR(3.5) },    /* Newfoundland Daylight */
  1349. #endif
  1350.     { "ast",    tZONE,     HOUR( 4) },    /* Atlantic Standard */
  1351.     { "adt",    tDAYZONE,  HOUR( 4) },    /* Atlantic Daylight */
  1352.     { "est",    tZONE,     HOUR( 5) },    /* Eastern Standard */
  1353.     { "edt",    tDAYZONE,  HOUR( 5) },    /* Eastern Daylight */
  1354.     { "cst",    tZONE,     HOUR( 6) },    /* Central Standard */
  1355.     { "cdt",    tDAYZONE,  HOUR( 6) },    /* Central Daylight */
  1356.     { "mst",    tZONE,     HOUR( 7) },    /* Mountain Standard */
  1357.     { "mdt",    tDAYZONE,  HOUR( 7) },    /* Mountain Daylight */
  1358.     { "pst",    tZONE,     HOUR( 8) },    /* Pacific Standard */
  1359.     { "pdt",    tDAYZONE,  HOUR( 8) },    /* Pacific Daylight */
  1360.     { "yst",    tZONE,     HOUR( 9) },    /* Yukon Standard */
  1361.     { "ydt",    tDAYZONE,  HOUR( 9) },    /* Yukon Daylight */
  1362.     { "hst",    tZONE,     HOUR(10) },    /* Hawaii Standard */
  1363.     { "hdt",    tDAYZONE,  HOUR(10) },    /* Hawaii Daylight */
  1364.     { "cat",    tZONE,     HOUR(10) },    /* Central Alaska */
  1365.     { "ahst",    tZONE,     HOUR(10) },    /* Alaska-Hawaii Standard */
  1366.     { "nt",    tZONE,     HOUR(11) },    /* Nome */
  1367.     { "idlw",    tZONE,     HOUR(12) },    /* International Date Line West */
  1368.     { "cet",    tZONE,     -HOUR(1) },    /* Central European */
  1369.     { "met",    tZONE,     -HOUR(1) },    /* Middle European */
  1370.     { "mewt",    tZONE,     -HOUR(1) },    /* Middle European Winter */
  1371.     { "mest",    tDAYZONE,  -HOUR(1) },    /* Middle European Summer */
  1372.     { "swt",    tZONE,     -HOUR(1) },    /* Swedish Winter */
  1373.     { "sst",    tDAYZONE,  -HOUR(1) },    /* Swedish Summer */
  1374.     { "fwt",    tZONE,     -HOUR(1) },    /* French Winter */
  1375.     { "fst",    tDAYZONE,  -HOUR(1) },    /* French Summer */
  1376.     { "eet",    tZONE,     -HOUR(2) },    /* Eastern Europe, USSR Zone 1 */
  1377.     { "bt",    tZONE,     -HOUR(3) },    /* Baghdad, USSR Zone 2 */
  1378. #if 0
  1379.     { "it",    tZONE,     -HOUR(3.5) },/* Iran */
  1380. #endif
  1381.     { "zp4",    tZONE,     -HOUR(4) },    /* USSR Zone 3 */
  1382.     { "zp5",    tZONE,     -HOUR(5) },    /* USSR Zone 4 */
  1383. #if 0
  1384.     { "ist",    tZONE,     -HOUR(5.5) },/* Indian Standard */
  1385. #endif
  1386.     { "zp6",    tZONE,     -HOUR(6) },    /* USSR Zone 5 */
  1387. #if    0
  1388.     /* For completeness.  NST is also Newfoundland Stanard, and SST is
  1389.      * also Swedish Summer. */
  1390.     { "nst",    tZONE,     -HOUR(6.5) },/* North Sumatra */
  1391.     { "sst",    tZONE,     -HOUR(7) },    /* South Sumatra, USSR Zone 6 */
  1392. #endif    /* 0 */
  1393.     { "wast",    tZONE,     -HOUR(7) },    /* West Australian Standard */
  1394.     { "wadt",    tDAYZONE,  -HOUR(7) },    /* West Australian Daylight */
  1395. #if 0
  1396.     { "jt",    tZONE,     -HOUR(7.5) },/* Java (3pm in Cronusland!) */
  1397. #endif
  1398.     { "cct",    tZONE,     -HOUR(8) },    /* China Coast, USSR Zone 7 */
  1399.     { "jst",    tZONE,     -HOUR(9) },    /* Japan Standard, USSR Zone 8 */
  1400. #if 0
  1401.     { "cast",    tZONE,     -HOUR(9.5) },/* Central Australian Standard */
  1402.     { "cadt",    tDAYZONE,  -HOUR(9.5) },/* Central Australian Daylight */
  1403. #endif
  1404.     { "east",    tZONE,     -HOUR(10) },    /* Eastern Australian Standard */
  1405.     { "eadt",    tDAYZONE,  -HOUR(10) },    /* Eastern Australian Daylight */
  1406.     { "gst",    tZONE,     -HOUR(10) },    /* Guam Standard, USSR Zone 9 */
  1407.     { "nzt",    tZONE,     -HOUR(12) },    /* New Zealand */
  1408.     { "nzst",    tZONE,     -HOUR(12) },    /* New Zealand Standard */
  1409.     { "nzdt",    tDAYZONE,  -HOUR(12) },    /* New Zealand Daylight */
  1410.     { "idle",    tZONE,     -HOUR(12) },    /* International Date Line East */
  1411.     {  NULL  }
  1412. };
  1413.  
  1414. /* Military timezone table. */
  1415. static TABLE const MilitaryTable[] = {
  1416.     { "a",    tZONE,    HOUR(  1) },
  1417.     { "b",    tZONE,    HOUR(  2) },
  1418.     { "c",    tZONE,    HOUR(  3) },
  1419.     { "d",    tZONE,    HOUR(  4) },
  1420.     { "e",    tZONE,    HOUR(  5) },
  1421.     { "f",    tZONE,    HOUR(  6) },
  1422.     { "g",    tZONE,    HOUR(  7) },
  1423.     { "h",    tZONE,    HOUR(  8) },
  1424.     { "i",    tZONE,    HOUR(  9) },
  1425.     { "k",    tZONE,    HOUR( 10) },
  1426.     { "l",    tZONE,    HOUR( 11) },
  1427.     { "m",    tZONE,    HOUR( 12) },
  1428.     { "n",    tZONE,    HOUR(- 1) },
  1429.     { "o",    tZONE,    HOUR(- 2) },
  1430.     { "p",    tZONE,    HOUR(- 3) },
  1431.     { "q",    tZONE,    HOUR(- 4) },
  1432.     { "r",    tZONE,    HOUR(- 5) },
  1433.     { "s",    tZONE,    HOUR(- 6) },
  1434.     { "t",    tZONE,    HOUR(- 7) },
  1435.     { "u",    tZONE,    HOUR(- 8) },
  1436.     { "v",    tZONE,    HOUR(- 9) },
  1437.     { "w",    tZONE,    HOUR(-10) },
  1438.     { "x",    tZONE,    HOUR(-11) },
  1439.     { "y",    tZONE,    HOUR(-12) },
  1440.     { "z",    tZONE,    HOUR(  0) },
  1441.     { NULL }
  1442. };
  1443.  
  1444.  
  1445.  
  1446.  
  1447. /* ARGSUSED */
  1448. static int
  1449. yyerror(s)
  1450.     char    *s;
  1451. {
  1452.   return 0;
  1453. }
  1454.  
  1455.  
  1456. static time_t
  1457. ToSeconds(Hours, Minutes, Seconds, Meridian)
  1458.     time_t    Hours;
  1459.     time_t    Minutes;
  1460.     time_t    Seconds;
  1461.     MERIDIAN    Meridian;
  1462. {
  1463.     if (Minutes < 0 || Minutes > 59 || Seconds < 0 || Seconds > 59)
  1464.     return -1;
  1465.     switch (Meridian) {
  1466.     case MER24:
  1467.     if (Hours < 0 || Hours > 23)
  1468.         return -1;
  1469.     return (Hours * 60L + Minutes) * 60L + Seconds;
  1470.     case MERam:
  1471.     if (Hours < 1 || Hours > 12)
  1472.         return -1;
  1473.     return (Hours * 60L + Minutes) * 60L + Seconds;
  1474.     case MERpm:
  1475.     if (Hours < 1 || Hours > 12)
  1476.         return -1;
  1477.     return ((Hours + 12) * 60L + Minutes) * 60L + Seconds;
  1478.     }
  1479.     /* NOTREACHED */
  1480. }
  1481.  
  1482.  
  1483. static time_t
  1484. Convert(Month, Day, Year, Hours, Minutes, Seconds, Meridian, DSTmode)
  1485.     time_t    Month;
  1486.     time_t    Day;
  1487.     time_t    Year;
  1488.     time_t    Hours;
  1489.     time_t    Minutes;
  1490.     time_t    Seconds;
  1491.     MERIDIAN    Meridian;
  1492.     DSTMODE    DSTmode;
  1493. {
  1494.     static int DaysInMonth[12] = {
  1495.     31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
  1496.     };
  1497.     time_t    tod;
  1498.     time_t    Julian;
  1499.     int        i;
  1500.  
  1501.     if (Year < 0)
  1502.     Year = -Year;
  1503.     if (Year < 100)
  1504.     Year += 1900;
  1505.     DaysInMonth[1] = Year % 4 == 0 && (Year % 100 != 0 || Year % 400 == 0)
  1506.             ? 29 : 28;
  1507.     if (Year < EPOCH || Year > 1999
  1508.      || Month < 1 || Month > 12
  1509.      /* Lint fluff:  "conversion from long may lose accuracy" */
  1510.      || Day < 1 || Day > DaysInMonth[(int)--Month])
  1511.     return -1;
  1512.  
  1513.     for (Julian = Day - 1, i = 0; i < Month; i++)
  1514.     Julian += DaysInMonth[i];
  1515.     for (i = EPOCH; i < Year; i++)
  1516.     Julian += 365 + (i % 4 == 0);
  1517.     Julian *= SECSPERDAY;
  1518.     Julian += yyTimezone * 60L;
  1519.     if ((tod = ToSeconds(Hours, Minutes, Seconds, Meridian)) < 0)
  1520.     return -1;
  1521.     Julian += tod;
  1522.     if (DSTmode == DSTon
  1523.      || (DSTmode == DSTmaybe && localtime(&Julian)->tm_isdst))
  1524.     Julian -= 60 * 60;
  1525.     return Julian;
  1526. }
  1527.  
  1528.  
  1529. static time_t
  1530. DSTcorrect(Start, Future)
  1531.     time_t    Start;
  1532.     time_t    Future;
  1533. {
  1534.     time_t    StartDay;
  1535.     time_t    FutureDay;
  1536.  
  1537.     StartDay = (localtime(&Start)->tm_hour + 1) % 24;
  1538.     FutureDay = (localtime(&Future)->tm_hour + 1) % 24;
  1539.     return (Future - Start) + (StartDay - FutureDay) * 60L * 60L;
  1540. }
  1541.  
  1542.  
  1543. static time_t
  1544. RelativeDate(Start, DayOrdinal, DayNumber)
  1545.     time_t    Start;
  1546.     time_t    DayOrdinal;
  1547.     time_t    DayNumber;
  1548. {
  1549.     struct tm    *tm;
  1550.     time_t    now;
  1551.  
  1552.     now = Start;
  1553.     tm = localtime(&now);
  1554.     now += SECSPERDAY * ((DayNumber - tm->tm_wday + 7) % 7);
  1555.     now += 7 * SECSPERDAY * (DayOrdinal <= 0 ? DayOrdinal : DayOrdinal - 1);
  1556.     return DSTcorrect(Start, now);
  1557. }
  1558.  
  1559.  
  1560. static time_t
  1561. RelativeMonth(Start, RelMonth)
  1562.     time_t    Start;
  1563.     time_t    RelMonth;
  1564. {
  1565.     struct tm    *tm;
  1566.     time_t    Month;
  1567.     time_t    Year;
  1568.  
  1569.     if (RelMonth == 0)
  1570.     return 0;
  1571.     tm = localtime(&Start);
  1572.     Month = 12 * tm->tm_year + tm->tm_mon + RelMonth;
  1573.     Year = Month / 12;
  1574.     Month = Month % 12 + 1;
  1575.     return DSTcorrect(Start,
  1576.         Convert(Month, (time_t)tm->tm_mday, Year,
  1577.         (time_t)tm->tm_hour, (time_t)tm->tm_min, (time_t)tm->tm_sec,
  1578.         MER24, DSTmaybe));
  1579. }
  1580.  
  1581.  
  1582. static int
  1583. LookupWord(buff)
  1584.     char        *buff;
  1585. {
  1586.     register char    *p;
  1587.     register char    *q;
  1588.     register const TABLE    *tp;
  1589.     int            i;
  1590.     int            abbrev;
  1591.  
  1592.     /* Make it lowercase. */
  1593.     for (p = buff; *p; p++)
  1594.     if (isupper(*p))
  1595.         *p = tolower(*p);
  1596.  
  1597.     if (strcmp(buff, "am") == 0 || strcmp(buff, "a.m.") == 0) {
  1598.     yylval.Meridian = MERam;
  1599.     return tMERIDIAN;
  1600.     }
  1601.     if (strcmp(buff, "pm") == 0 || strcmp(buff, "p.m.") == 0) {
  1602.     yylval.Meridian = MERpm;
  1603.     return tMERIDIAN;
  1604.     }
  1605.  
  1606.     /* See if we have an abbreviation for a month. */
  1607.     if (strlen(buff) == 3)
  1608.     abbrev = 1;
  1609.     else if (strlen(buff) == 4 && buff[3] == '.') {
  1610.     abbrev = 1;
  1611.     buff[3] = '\0';
  1612.     }
  1613.     else
  1614.     abbrev = 0;
  1615.  
  1616.     for (tp = MonthDayTable; tp->name; tp++) {
  1617.     if (abbrev) {
  1618.         if (strncmp(buff, tp->name, 3) == 0) {
  1619.         yylval.Number = tp->value;
  1620.         return tp->type;
  1621.         }
  1622.     }
  1623.     else if (strcmp(buff, tp->name) == 0) {
  1624.         yylval.Number = tp->value;
  1625.         return tp->type;
  1626.     }
  1627.     }
  1628.  
  1629.     for (tp = TimezoneTable; tp->name; tp++)
  1630.     if (strcmp(buff, tp->name) == 0) {
  1631.         yylval.Number = tp->value;
  1632.         return tp->type;
  1633.     }
  1634.  
  1635.     if (strcmp(buff, "dst") == 0) 
  1636.     return tDST;
  1637.  
  1638.     for (tp = UnitsTable; tp->name; tp++)
  1639.     if (strcmp(buff, tp->name) == 0) {
  1640.         yylval.Number = tp->value;
  1641.         return tp->type;
  1642.     }
  1643.  
  1644.     /* Strip off any plural and try the units table again. */
  1645.     i = strlen(buff) - 1;
  1646.     if (buff[i] == 's') {
  1647.     buff[i] = '\0';
  1648.     for (tp = UnitsTable; tp->name; tp++)
  1649.         if (strcmp(buff, tp->name) == 0) {
  1650.         yylval.Number = tp->value;
  1651.         return tp->type;
  1652.         }
  1653.     buff[i] = 's';        /* Put back for "this" in OtherTable. */
  1654.     }
  1655.  
  1656.     for (tp = OtherTable; tp->name; tp++)
  1657.     if (strcmp(buff, tp->name) == 0) {
  1658.         yylval.Number = tp->value;
  1659.         return tp->type;
  1660.     }
  1661.  
  1662.     /* Military timezones. */
  1663.     if (buff[1] == '\0' && isalpha(*buff)) {
  1664.     for (tp = MilitaryTable; tp->name; tp++)
  1665.         if (strcmp(buff, tp->name) == 0) {
  1666.         yylval.Number = tp->value;
  1667.         return tp->type;
  1668.         }
  1669.     }
  1670.  
  1671.     /* Drop out any periods and try the timezone table again. */
  1672.     for (i = 0, p = q = buff; *q; q++)
  1673.     if (*q != '.')
  1674.         *p++ = *q;
  1675.     else
  1676.         i++;
  1677.     *p = '\0';
  1678.     if (i)
  1679.     for (tp = TimezoneTable; tp->name; tp++)
  1680.         if (strcmp(buff, tp->name) == 0) {
  1681.         yylval.Number = tp->value;
  1682.         return tp->type;
  1683.         }
  1684.  
  1685.     return tID;
  1686. }
  1687.  
  1688.  
  1689. static int
  1690. yylex()
  1691. {
  1692.     register char    c;
  1693.     register char    *p;
  1694.     char        buff[20];
  1695.     int            Count;
  1696.     int            sign;
  1697.  
  1698.     for ( ; ; ) {
  1699.     while (isspace(*yyInput))
  1700.         yyInput++;
  1701.  
  1702.     if (isdigit(c = *yyInput) || c == '-' || c == '+') {
  1703.         if (c == '-' || c == '+') {
  1704.         sign = c == '-' ? -1 : 1;
  1705.         if (!isdigit(*++yyInput))
  1706.             /* skip the '-' sign */
  1707.             continue;
  1708.         }
  1709.         else
  1710.         sign = 0;
  1711.         for (yylval.Number = 0; isdigit(c = *yyInput++); )
  1712.         yylval.Number = 10 * yylval.Number + c - '0';
  1713.         yyInput--;
  1714.         if (sign < 0)
  1715.         yylval.Number = -yylval.Number;
  1716.         return sign ? tSNUMBER : tUNUMBER;
  1717.     }
  1718.     if (isalpha(c)) {
  1719.         for (p = buff; isalpha(c = *yyInput++) || c == '.'; )
  1720.         if (p < &buff[sizeof buff - 1])
  1721.             *p++ = c;
  1722.         *p = '\0';
  1723.         yyInput--;
  1724.         return LookupWord(buff);
  1725.     }
  1726.     if (c != '(')
  1727.         return *yyInput++;
  1728.     Count = 0;
  1729.     do {
  1730.         c = *yyInput++;
  1731.         if (c == '\0')
  1732.         return c;
  1733.         if (c == '(')
  1734.         Count++;
  1735.         else if (c == ')')
  1736.         Count--;
  1737.     } while (Count > 0);
  1738.     }
  1739. }
  1740.  
  1741.  
  1742. time_t
  1743. get_date(p, now)
  1744.     char        *p;
  1745.     struct timeb    *now;
  1746. {
  1747.     struct tm        *tm;
  1748.     struct timeb    ftz;
  1749.     time_t        Start;
  1750.     time_t        tod;
  1751.  
  1752.     yyInput = p;
  1753.     if (now == NULL) {
  1754.         now = &ftz;
  1755. #if    !defined(HAVE_FTIME)
  1756.     (void)time(&ftz.time);
  1757.     /* Set the timezone global. */
  1758.     tzset();
  1759.     {
  1760. #if defined(sgi)
  1761.         ftz.timezone = (int) _timezone / 60;
  1762. #else /* not sgi */
  1763. #ifdef __386BSD__
  1764.         ftz.timezone = 0;
  1765. #else /* neither sgi nor 386BSD */
  1766. #if defined (USG) || defined(__BORLANDC__)
  1767.         extern time_t timezone;
  1768.  
  1769.         ftz.timezone = (int) timezone / 60;
  1770. #else /* neither sgi nor 386BSD nor USG */
  1771.         struct timeval tv;
  1772.         struct timezone tz;
  1773.  
  1774.         gettimeofday (&tv, &tz);
  1775.         ftz.timezone = (int) tz.tz_minuteswest;
  1776. #endif /* neither sgi nor 386BSD nor USG */
  1777. #endif /* neither sgi nor 386BSD */
  1778. #endif /* not sgi */
  1779.     }
  1780. #else /* HAVE_FTIME */
  1781.     (void)ftime(&ftz);
  1782. #endif /* HAVE_FTIME */
  1783.     }
  1784.  
  1785.     tm = localtime(&now->time);
  1786.     yyYear = tm->tm_year;
  1787.     yyMonth = tm->tm_mon + 1;
  1788.     yyDay = tm->tm_mday;
  1789.     yyTimezone = now->timezone;
  1790.     yyDSTmode = DSTmaybe;
  1791.     yyHour = 0;
  1792.     yyMinutes = 0;
  1793.     yySeconds = 0;
  1794.     yyMeridian = MER24;
  1795.     yyRelSeconds = 0;
  1796.     yyRelMonth = 0;
  1797.     yyHaveDate = 0;
  1798.     yyHaveDay = 0;
  1799.     yyHaveRel = 0;
  1800.     yyHaveTime = 0;
  1801.     yyHaveZone = 0;
  1802.  
  1803.     if (yyparse()
  1804.      || yyHaveTime > 1 || yyHaveZone > 1 || yyHaveDate > 1 || yyHaveDay > 1)
  1805.     return -1;
  1806.  
  1807.     if (yyHaveDate || yyHaveTime || yyHaveDay) {
  1808.     Start = Convert(yyMonth, yyDay, yyYear, yyHour, yyMinutes, yySeconds,
  1809.             yyMeridian, yyDSTmode);
  1810.     if (Start < 0)
  1811.         return -1;
  1812.     }
  1813.     else {
  1814.     Start = now->time;
  1815.     if (!yyHaveRel)
  1816.         Start -= ((tm->tm_hour * 60L + tm->tm_min) * 60L) + tm->tm_sec;
  1817.     }
  1818.  
  1819.     Start += yyRelSeconds;
  1820.     Start += RelativeMonth(Start, yyRelMonth);
  1821.  
  1822.     if (yyHaveDay && !yyHaveDate) {
  1823.     tod = RelativeDate(Start, yyDayOrdinal, yyDayNumber);
  1824.     Start += tod;
  1825.     }
  1826.  
  1827.     /* Have to do *something* with a legitimate -1 so it's distinguishable
  1828.      * from the error return value.  (Alternately could set errno on error.) */
  1829.     return Start == -1 ? 0 : Start;
  1830. }
  1831.  
  1832.  
  1833. #if    defined(TEST)
  1834.  
  1835. /* ARGSUSED */
  1836. main(ac, av)
  1837.     int        ac;
  1838.     char    *av[];
  1839. {
  1840.     char    buff[128];
  1841.     time_t    d;
  1842.  
  1843.     (void)printf("Enter date, or blank line to exit.\n\t> ");
  1844.     (void)fflush(stdout);
  1845.     while (gets(buff) && buff[0]) {
  1846.     d = get_date(buff, (struct timeb *)NULL);
  1847.     if (d == -1)
  1848.         (void)printf("Bad format - couldn't convert.\n");
  1849.     else
  1850.         (void)printf("%s", ctime(&d));
  1851.     (void)printf("\t> ");
  1852.     (void)fflush(stdout);
  1853.     }
  1854.     exit(0);
  1855.     /* NOTREACHED */
  1856. }
  1857. #endif    /* defined(TEST) */
  1858.